package com.yunzhong.appointment.essentialinformation.controller;

import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.entity.Hospital;
import com.yunzhong.appointment.essentialinformation.service.IHostipalService;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 王仁海
 * @author ThinkPad
 * @desc 医院简介
 */
@Controller
@RequestMapping("baseinfo")
public class HostipalController {

    @Autowired
    private IHostipalService hostipalService;

    /**
     * 医院简介查询方法
     * @param request
     * @param mm
     * @return
     */
    @RequestMapping("showHospitalInfo")
    public String showHospitalInfo(HttpServletRequest request, ModelMap mm) {
        //接收前台数据
        PageData pd = new PageData(request);
        //查询数据
        List<Hospital> varList = hostipalService.queryHostipal(pd);
        //得到分页数据
        PageInfo page = new PageInfo(varList);
        mm.put("page", page);
        mm.put("pd", pd);
        return "system/essentialinformation/hostipal/listhostipal";
    }

    /**
     * @param mp
     * @param id
     * @return
     * @desc 转到修改页面
     */
    @RequestMapping("editshowHospitalInfo")
    public String editpage(ModelMap mp, String id,String pageNum) {
        Hospital byId = hostipalService.queryById(id);
        mp.put("byId", byId);
        mp.put("pageNum", pageNum);
        return "system/essentialinformation/hostipal/edithostipal";
    }

    /**
     * 修改保存
     *
     * @param yyjj
     * @return
     */
    @RequestMapping("editsaveshowHospitalInfo")
    public String editsave(Hospital yyjj) {
        hostipalService.edit(yyjj);
        return "redirect:showHospitalInfo";
    }

}
